﻿using System;


using System.Text;
using IAM.Interface.Model.Interface;
using System.Xml;
using IAM.Interface.Model.ENUM;

namespace IAM.Interface.Model
{
    /// <summary>
    /// 可代理模块集合【Module】
    /// </summary>
    public class Modules : AbstractConvertObject, IConvertXml
    {
        #region 构造函数
        public Modules()
        {
            _modules = new System.Collections.ArrayList();
        }
        #endregion
        #region 属性
        private System.Collections.ArrayList _modules= null;
        /// <summary>
        /// 模块的数量 
        /// </summary>
        public int Count
        {
            get
            {
                return this.Items.Count;
            }
        }
        /// <summary>
        /// 可代理模块集合【Module】
        /// </summary>
        public System.Collections.ArrayList Items
        {
            get
            {
                return _modules;
            }
            set
            {
                _modules = value;
            }
        }
        #endregion
        #region IConvertXml

        public string XMLBoday
        {
            get
            {
                StringBuilder _xml = new StringBuilder();
                _xml.Append(" <Modules ");
                _xml.Append(" Count=\"" + this.Count + "\"");
                _xml.Append(" >");
                foreach (object module in this.Items)
                {
                    _xml.Append(((Module)module).XML);
                }
                return _xml.ToString();
            }


        }

        public string XMLFinis
        {
            get
            {
                return "</Modules>";
            }
        }
        public string XML
        {
            get
            {
                return XMLBoday + XMLFinis;
            }
        }
        #endregion
        #region AbstractConvertObject
        public override object ConvertToObject()
        {
            foreach (XmlNode xn in this.CurrentXmlNode.ChildNodes)
            {
                Module module = new Module();
                module.CurrentXmlNode = xn;
                module = (Module)module.ConvertToObject();
                this.Items.Add(module);
            }
            return this;
        }
        #endregion
    }
}
